﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Windows.Data;
using VNet.VisiSuite.Common.Helpers;

namespace VNet.VisiSuite.Common.Converters
{
    public class BarMarkerConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
                return null;

            var property_infos = value.GetType().GetProperties();

            var key = property_infos.FirstOrDefault(p => p.Name == "Key");
            if (key == null)
                return null;

            var string_key = (string) key.GetValue(value, null);

            var time = property_infos.FirstOrDefault(p => p.Name == string_key + "_Time");

            if (time == null)
                return null;

            var t = (double) time.GetValue(value, null);
            TimeSpan time_span = TimeSpan.FromHours(t);
            return time_span.ToString(@"hh\:mm\:ss");
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
